﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;

namespace FollowMe.API.App_Start
{
    public class DateTimeConvertor : DateTimeConverterBase
    {
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            return DateTime.Parse(reader.Value.ToString());
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            //See MS doc for date formats:
            //http://msdn.microsoft.com/en-us/library/zdtaw1bw%28v=vs.110%29.aspx
            writer.WriteValue(((DateTime)value).ToString("R"));
        }
    }
}